package com.gengine.manager
{
	import flash.external.*;
	import flash.net.*;
	
	public class BrowerManager extends Object
	{
		//private static var jsCode:Class = BrowerManager_jsCode;
		private static var _instance:BrowerManager;
		
		public function BrowerManager()
		{
			if (_instance != null)
			{
				throw "BrowerManager 为单例";
			}
			
		}
		
		public function get url() : String
		{
			if (!ExternalInterface.available)
			{
				return null;
			}
			return ExternalInterface.call("BrowerManager.getURL");
		}
		
		public function get baseUrl() : String
		{
			if (!ExternalInterface.available)
			{
				return null;
			}
			var _loc_1:* = this.url;
			var _loc_2:* = _loc_1.indexOf("#");
			if (_loc_2 > 0)
			{
				return _loc_1.substr(0, (_loc_2 - 1));
			}
			return _loc_1;
		}
		
		public function set title(param1:String) : void
		{
			if (!ExternalInterface.available)
			{
				
			}
			ExternalInterface.call("BrowerManager.setTitle", param1);
			
		}
		
		public function get title() : String
		{
			if (!ExternalInterface.available)
			{
				return null;
			}
			return ExternalInterface.call("BrowerManager.getTitle");
		}
		
		public function set urlVariables(param1:URLVariables) : void
		{
			if (!ExternalInterface.available)
			{
				
			}
			var _loc_2:String = "";
			var _loc_3:* = param1.toString();
			if (_loc_3.length > 0)
			{
				_loc_2 = _loc_2 + ("#" + _loc_3);
			}
			ExternalInterface.call("BrowerManager.setUrlVariables", _loc_2);
			
		}
		
		public function get urlVariables() : URLVariables
		{
			if (!ExternalInterface.available)
			{
				return null;
			}
			var _loc_1:* = this.url;
			var _loc_2:* = _loc_1.indexOf("#");
			if (_loc_2 > 0)
			{
				return new URLVariables(_loc_1.substr((_loc_2 + 1)));
			}
			return new URLVariables();
		}
		
		public function addFavorite(param1:String = null, param2:String = null) : void
		{
			var title:* = param1;
			var url:* = param2;
			if (!ExternalInterface.available)
			{
				
			}
			if (!url)
			{
				url = this.url;
			}
			if (!title)
			{
				title = this.title;
			}
			try
			{
				ExternalInterface.call("BrowerManager.addFavorite", url, title);
			}
			catch (e:Error)
			{
			}
			
		}
		
		public function setHomePage(param1:String = null) : void
		{
			if (!ExternalInterface.available)
			{
				
			}
			if (!param1)
			{
				param1 = this.url;
			}
			ExternalInterface.call("BrowerManager.setHomePage", param1);
			
		}
		
		public function setCookie(param1:String, param2:String, param3:Date = null, param4:Boolean = false) : void
		{
			if (!ExternalInterface.available)
			{
				
			}
			var _loc_5:* = new Date(new Date().time + 1000 * 86400 * 365);
			param3 = new Date(new Date().time + 1000 * 86400 * 365);
			ExternalInterface.call("BrowerManager.setCookie", param1, param2, param3.time, param4);
			
		}
		
		public function getCookie(param1:String) : String
		{
			if (!ExternalInterface.available)
			{
				return null;
			}
			return ExternalInterface.call("BrowerManager.getCookie", param1);
		}
		
		public function confirmClose(param1:String = "确认退出？") : void
		{
			if (!ExternalInterface.available)
			{
				
			}
			if (param1)
			{
				ExternalInterface.call("BrowerManager.confirmClose", param1);
			}
			else
			{
				ExternalInterface.call("BrowerManager.confirmClose");
			}
			
		}
		
		public function alert(... args) : void
		{
			if (!ExternalInterface.available)
			{
				
			}
			ExternalInterface.call("alert", args.toString());
			
		}
		
		public function reload() : void
		{
			if (!ExternalInterface.available)
			{
				
			}
			ExternalInterface.call("location.reload");
			
		}
		
		public function disableScroll(param1:String = null) : void
		{
			if (!ExternalInterface.available)
			{
				
			}
			ExternalInterface.call("BrowerManager.disableScroll", param1);
			
		}
		
		public function getUrl(param1:String, param2:String = "_self") : void
		{
			var _loc_3:String = null;
			if (param1.substr(0, 11) == "javascript:" && ExternalInterface.available)
			{
				_loc_3 = param1.substr(11);
				if (param1.indexOf("(") == -1 && param1.indexOf(")") == -1)
				{
					_loc_3 = _loc_3 + "()";
				}
				ExternalInterface.call("eval", _loc_3);
			}
			else
			{
				navigateToURL(new URLRequest(param1), param2);
			}
			
		}
		
		public static function get instance() : BrowerManager
		{
			if (_instance == null)
			{
				_instance = new BrowerManager;
			}
			return _instance;
		}
		
	}
}
